
package LoadFromDatabase;

import java.sql.ResultSet;
import java.sql.Statement;

public class LoadCrossingsFromDB extends Thread {

    private Statement statement;
    private String location;
    
    public LoadCrossingsFromDB(Statement statement, String location){
        this.location = location;
        this.statement = statement;
    }

    @Override
    public void run(){

        //CrossingCollection crossingCollection = new CrossingCollection();
        String data = "";
    	try{
            System.out.println("Start Loading Crossings");
            ResultSet resultSet = statement.executeQuery("SELECT id,long,lat FROM crossing WHERE "+location+" AND partnr=0 ORDER BY id,partnr");
            System.out.println("Finished Loading Crossings");
            System.out.println("Start Writing File Crossings");
            while (resultSet.next())
            {
                int db_id=(int)resultSet.getLong(1);
                double db_long=resultSet.getDouble(2);
                double db_lat=resultSet.getDouble(3);
                data += db_id + " " + db_long + " " + db_lat + "\r\n";
            }
            resultSet.close();
        }catch(Exception ex){
            System.out.println("Error in Execute Crossings"+ex.toString());
            ex.printStackTrace();
            System.exit(1);
        }
        WriteData.write(data, FileNames.fileNameCrossings);
        System.out.println("Finished Writing File Crossings");
    }
}
